//
//  InvestReportViewController.m
//  WBBaseProject
//
//  Created by 吴斌 on 2018/4/10.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "InvestReportViewController.h"
#import "XYHomeNavigationView.h"
#import "InvestMoneyCell.h"
#import "MyBidRecordCell.h"
#import "InvestReportHeadView.h"
#import "OverduePaymentCell.h"
//首页导航栏滚动距离
#define NAVBAR_CHANGE_POINT 50

static NSString * const InvestMoneyCellReuseId = @"InvestMoneyCell";
static NSString * const OverduePaymentCellReuseId = @"OverduePaymentCell";
@interface InvestReportViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
/** <#注释#> */
@property (nonatomic, strong) XYHomeNavigationView *naviView;
/** <#注释#> */
@property (nonatomic,strong) InvestReportHeadView *headView;

@end

@implementation InvestReportViewController

#pragma mark - 生命周期 Life Circle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self registerCell];
    [self.view addSubview:self.tableView];
    self.navigationController.navigationBar.hidden = YES;
    
    XYHomeNavigationView *naviView = [[XYHomeNavigationView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kNavigationBarHeight)];
    _naviView = naviView;
    _naviView.titleLb.text = @"投资账户";
    [_naviView.rightBtn removeFromSuperview];
    [_naviView.leftBtn addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:naviView];
}
- (void)pop
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)registerCell
{
    [self.tableView registerNib:[UINib nibWithNibName:@"InvestMoneyCell" bundle:nil] forCellReuseIdentifier:InvestMoneyCellReuseId];
    [self.tableView registerNib:[UINib nibWithNibName:@"OverduePaymentCell" bundle:nil] forCellReuseIdentifier:OverduePaymentCellReuseId];
    //    [self.tableView registerClass:[BorrowOrInvestCell class] forCellReuseIdentifier:BorrowOrInvestCellReuseId];
    //    [self.tableView registerClass:[PlatformDataCell class] forCellReuseIdentifier:PlatformDataCellReuseId];
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.row == 0 || indexPath.row == 1) {
        InvestMoneyCell *cell = [tableView dequeueReusableCellWithIdentifier:InvestMoneyCellReuseId forIndexPath:indexPath];
        return cell;
    }else{
        OverduePaymentCell *cell = [tableView dequeueReusableCellWithIdentifier:OverduePaymentCellReuseId forIndexPath:indexPath];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return indexPath.row == 2 ? 140.0f : 150.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    
    
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat cellOffy = scrollView.contentOffset.y;
    if (cellOffy < 0) {
        self.naviView.hidden = YES;
    }else{
        self.naviView.hidden = NO;
    }
    
    if (cellOffy > NAVBAR_CHANGE_POINT) {
        
        [self.naviView changeColorWithState:YES];
        self.naviView.backgroundColor = WB_RGBAColor(255, 255, 255, 0.8);
        [WB_SharedApplication setStatusBarStyle:UIStatusBarStyleDefault animated:true];
    }else {
        CGFloat alpa = cellOffy/NAVBAR_CHANGE_POINT;
        if (alpa > 0.8) {
            self.naviView.backgroundColor = WB_RGBAColor(255, 255, 255, 0.8);
            return ;
        }
        [self.naviView changeColorWithState:NO];
        self.naviView.backgroundColor = WB_RGBAColor(255, 255, 255, alpa);
        [WB_SharedApplication setStatusBarStyle:UIStatusBarStyleLightContent animated:true];
    }
}


#pragma mark - 懒加载  Lazy Load
- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
        _tableView.backgroundColor = WB_HEX_COLOR(0xf0f0f0);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableHeaderView = self.headView;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

- (InvestReportHeadView *)headView
{
    if (_headView == nil) {
        _headView = [[NSBundle mainBundle] loadNibNamed:@"InvestReportHeadView" owner:self options:nil].firstObject;
        _headView.frame = CGRectMake(0, 0, kScreenWidth, 210);
    }
    return _headView;
}

@end
